#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

// https://leetcode.cn/contest/weekly-contest-453/problems/count-the-number-of-computer-unlocking-permutations/
// Q2. 统计计算机解锁顺序排列数

class Solution {
    int mod = 1000000007;
public:
    long long recursionTry(vector<int>& compleity, int begin, int pre){
        int n = compleity.size();
        if(begin == n){
            return 1;
        }
        long long ret = 0;
        for (int i = begin; i < n; i++)
        {
            if(compleity[i] > pre){
                ret = (ret + recursionTry(compleity, i + 1, pre)) % mod;
                continue;
            }
            return 0;
        }
        return ret;
    }
    int countPermutations(vector<int>& complexity) {
        int pre = complexity[0];
        sort(complexity.begin(), complexity.end());
        if(complexity[0] != pre || complexity[1] == pre){
            return 0;
        }
        return recursionTry(complexity, 1, pre);
    }
};

int main()
{
    vector<int> nums{155, 437, 368, 168};
    Solution solution{};
    cout << solution.countPermutations(nums) << endl;
    return 0;
}